package emby.stmt;

import emby.expr.Expression;
import emby.expr.Variable;
import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

public class Assignment extends Statement{

	private static final long serialVersionUID = 4435336088184325198L;
	Variable variable;
	Expression value;
	public Assignment(Variable var, Expression val){
		variable=var;
		value=val;
	}

	@Override
	public Object eval(Scope s){
		Object expr = value.eval(s);
		variable.setVar(s, expr);

		return null;
	}

	public String toString(){
		if( variable ==null){
			return "{Assign_stmt}";
		}
		return "{Assignment: "+variable+" to "+value+"}";
	}
	
	public void codify(IEmbyCodifier ec){
		ec.assignment(variable, value);
	}

}
